package cn.yanhu.kuwanapp.common.activity

import android.content.Context
import android.content.Intent
import androidx.activity.viewModels
import androidx.core.view.isVisible
import cn.yanhu.kuwanapp.common.viewmodels.CommonViewModel
import cn.yanhu.kuwanapp.utils.helper.WebViewHelper

/**
 * 类描述:通用带标题webview
 * @author：woochen
 * create at：2021/7/25 3:23 PM
*/
class CommonWebviewActivity : BaseTitleWebviewActivity<CommonViewModel>() {

    private val mCommonViewModel by viewModels<CommonViewModel>()

    private val mUrl by lazy {
        intent.getStringExtra(EXTRA_LINK)?:""
    }

    private val isShowTitle by lazy {
        intent.getBooleanExtra(EXTRA_SHOW_TITLE,false)
    }

    override fun initContentData() {
        val titleView = getTitleView()
        titleView.isVisible = isShowTitle
        WebViewHelper.loadUrl(getWebView(),mUrl)
    }



    companion object{
        private const val EXTRA_LINK = "extra_link"
        private const val EXTRA_SHOW_TITLE = "extra_show_title"
        fun start(context: Context, link:String?,showTitle:Boolean = false){
            val intent = Intent(context, CommonWebviewActivity::class.java)
            intent.putExtra(EXTRA_LINK,link?:"")
            intent.putExtra(EXTRA_SHOW_TITLE,showTitle)
            context.startActivity(intent)
        }
    }
}